#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年4月28日

@author: chenyongbing
'''
import sys,os
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]

sys.path.append('../..')

from base.retail_datas import myRetailDatas

from base.zhimind_datas import myZhimindDatas



citys = '北京,上海,广州,深圳,南京,杭州,武汉,成都,太原,黑龙江,重庆,武汉,沈阳,福州,南宁,郑州,石家庄,长沙,南昌,济南,呼和浩特,乌鲁木齐'
timeList = [['2015-02-01','2015-02-28'],['2015-03-01','2015-03-31'],['2015-04-01','2015-04-30']]
citylist = citys.split(',')
for city in citylist:
    groups = myRetailDatas.get_groups_by_region( city=city)
    if groups ==None or len(groups)==0:continue
    groups_str = myRetailDatas.conv_tuple_to_str(groups)
    print city
    for st,et in timeList:
        #mac数量
#         query = 'select count(distinct mac) from ('+\
#                     'select mac as mac,factory as factory from mac_customer_stats where dgroup in (%s) and day between "%s" and "%s"'%(groups_str,st,et)+\
#                     ' union all '+\
#                     'select mws.mac as mac,mf.factory_en as factory from mac_walkby_stats mws,mac_factory mf where dgroup in (%s) and day between "%s" and "%s" and lower(left(mws.mac,8))=lower(mf.mac)'%(groups_str,st,et)+\
#                 ') as allcustomer'
        
        query = 'select count(distinct mac) from mac_customer_stats where dgroup in (%s) and day between "%s" and "%s"'%(groups_str,st,et)
        #print query
        #苹果 mac数量、比例
        query2 = query + ' and factory="Apple"'
        #真实mac数量、比例
        
        query3 = query + ' and substring(LPAD(conv(left(mac,2),16,2),8,0),7,1)=0'
#     
#         print query
#         print query2
#         print query3
        print "%s-%s"%(st,et),
        print myZhimindDatas.myZhimind.SelectCount(query),
        print myZhimindDatas.myZhimind.SelectCount(query2),
        print myZhimindDatas.myZhimind.SelectCount(query3),
    print ''